package com.newblog.common;

import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.util.UUID;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2023-12-15
 * Time:9:38
 * Text：
 */
public class PasswordUtils {
    public static String encrypt(String password){
        //盐值
        String salt= UUID.randomUUID().toString().replace("-","");
        //盐值+密码
        String finalPassword= DigestUtils.md5DigestAsHex((salt+password).getBytes(StandardCharsets.UTF_8));
        return salt+"$"+finalPassword;
    }

    public static void main(String[] args) {
        System.out.println(encrypt("123"));
        System.out.println(encrypt("123"));
        System.out.println(encrypt("123"));

    }
}
